package com.demo.study.creative.d02_abstractFactory;

import com.demo.study.creative.d02_abstractFactory.expand.SenderProvider;
import com.demo.study.creative.d02_abstractFactory.expand.SmsFactory;
import com.demo.study.creative.d02_abstractFactory.impl.MailSender;
import com.demo.study.creative.d02_abstractFactory.normal.OrdinaryFactory;
import com.demo.study.creative.d02_abstractFactory.normal.StaticFactory;

/**
 * @author Baymax
 * @since 2021/1/18
 */
public class FactoryMain {
    public static void main(String[] args) {
//        ordinaryFactory();
//        staticFactory();
        abstractFactory();
    }

    // 抽象工厂
    private static void abstractFactory() {
//        SenderProvider provider = new MailFactory();
        SenderProvider provider = new SmsFactory();

        Sender sender = provider.produce();
        sender.send();
    }

    // 静态工厂
    private static void staticFactory() {
        Sender mailSender = StaticFactory.getMailSender();
        mailSender.send();

        Sender smsSender = StaticFactory.getSmsSender();
        smsSender.send();
    }

    // 普通工厂
    private static void ordinaryFactory() {
        Sender sender = OrdinaryFactory.produceSender("sms");
        sender.send();

        Sender sender1 = OrdinaryFactory.getSender(MailSender.class);
        sender1.send();
    }
}
